fix(profile): dispose stale ECharts instance in initEChart - #29
Merged
Merged
Conversation
echarts.init reuses an existing instance on a DOM node, and setOption merges by default, so switching profiles left a previous person's Contributions Over Time series (e.g. AE Committee Service / ArtiFinder) rendered for the next person. Dispose any pre-existing instance before re-init so every render starts from a clean slate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On the profile page, switching from one person to another left the Contributions Over Time chart showing the previous person's series. For example, going to Anjo Vahldiek-Oberwagner (who has AE Committee Service) and then changing the name to Christian Rossow showed the same early "AE Committee Service" bars that belonged to Anjo.
Root cause
echarts.init(el)returns the existing instance already attached to a DOM node rather than a fresh one. The profile page re-callsinitECharton the same#timelineChartelement on every profile switch, andrenderContributionChartthen callssetOption(...)with the default merge semantics. ECharts merges series by index, so when the new person has fewer series (e.g. only "Artifact Papers"), the previous person's higher-index series ("ArtiFinder (discovered)", "AE Committee Service") are never removed.Fix
Dispose any pre-existing ECharts instance on the element inside
initEChartbefore creating a new one, so every re-render starts from a clean slate. Because the fix is centralized ininitEChart, it also resolves the same latent staleness for any other chart that re-renders on the same element (e.g. the ranking-history chart), and it preserves theming since the fresh instance re-applies the light/dark baseline. The wrappeddisposealso disconnects theResizeObserver, so there is no observer leak.R.initEChart = function(el) { if (typeof el === 'string') el = document.getElementById(el); if (!el) return null; + var existing = echarts.getInstanceByDom(el); + if (existing) existing.dispose(); var chart = echarts.init(el, null, { renderer: 'canvas' });Testing